package com.like.banzipao.server.model

val pokerComparator = compareBy<Poker> { it.getValue() }.thenByDescending { it.suit }

/**
 * 扑克牌
 */
data class Poker(val id: Int, val name: String, val suit: Suit) {
    var state: PokerState = PokerState.NORMAL
    var holderUserId: Int = -1

    constructor(id: Int, value: Int, suit: Suit) : this(
        id, when (value) {
            11 -> "J"
            12 -> "Q"
            13 -> "K"
            14 -> "A"
            15 -> "2"
            else -> value.toString()
        }, suit
    )

    fun getValue() = when (name) {
        "J" -> 11
        "Q" -> 12
        "K" -> 13
        "A" -> 14
        "2" -> 15
        else -> name.toInt()
    }

    override fun toString(): String {
        return "${suit.des}$name"
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is Poker) return false

        if (id != other.id) return false

        return true
    }

    override fun hashCode(): Int {
        return id
    }

}

/**
 * 花色
 */
enum class Suit(val des: String) {
    SPADE("黑桃"), HEART("红桃"), CLUB("梅花"), DIAMOND("方片");
}

/**
 * 扑克牌状态
 */
enum class PokerState(val des: String) {
    NORMAL("正常"), DRAW_DECKS("换牌牌堆"), DRAW_WAIT("等待换牌"), PLAY_PLAYED("玩牌已出"), PLAY_DECKS("玩牌牌堆"), PLAY_GOT("玩牌得牌"),
}
